package com.lianbang.pharmacy.module.medicine.category

import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import cn.ubest.mvvmcore.base.BaseFragment
import cn.ubest.mvvmcore.databinding.IncludeListWithoutRefreshBinding
import com.chad.library.adapter.base.entity.node.BaseNode
import com.lianbang.pharmacy.R
import com.lianbang.pharmacy.adapter.ProductListAdapter
import com.lianbang.pharmacy.bean.*
import com.lianbang.pharmacy.vm.MedicineVM

class ProductCategoryFragment : BaseFragment<MedicineVM, IncludeListWithoutRefreshBinding>() {

    private val mAdapter by lazy {
        ProductListAdapter()
    }

    private var mCategoryList: List<MedicineCategory2ListBean>? = null

    companion object {
        fun newInstance(categoryList: List<MedicineCategory2ListBean>?): ProductCategoryFragment {
            val fragment = ProductCategoryFragment()
            fragment.mCategoryList = categoryList
            return fragment
        }
    }

    override fun initData(arguments: Bundle?) {

    }

    override fun initView(view: View) {
        mBinding?.rvList?.apply {
            layoutManager = GridLayoutManager(activity, 3)
            adapter = mAdapter

            mAdapter.setOnItemClickListener { _, _, position ->
                val item = mAdapter.data[position]
                if (item is MedicineCategory2ListBean) {

                } else if (item is MedicineCategory3ListBean) {

                }
            }
        }
    }

    override fun loadData() {
        mCategoryList?.also {
            mAdapter.replaceData(it)
        }
    }

    override fun initLayout(): Int {
        return R.layout.include_list_without_refresh
    }
}
